package com.epaylinks.serviceprovider.controller;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.epaylinks.serviceprovider.domain.User;
import com.epaylinks.serviceprovider.service.MQSendService;
import com.epaylinks.serviceprovider.service.UserService;




@RestController
public class HelloController {
	
	private final Logger logger = Logger.getLogger(getClass());
	
	@Autowired
	private DiscoveryClient client;
	
	@Autowired
    private UserService userService;
	
	@Autowired
	private MQSendService mqSendService;
    
    @RequestMapping(value="/user",method=RequestMethod.GET)
    public List<User> getByGradeNm(){
        return userService.getAllUsers();
    }
    
	
	@RequestMapping(value="/hello",method=RequestMethod.GET)
	public String index()
	{
		logger.info("-------------------------------HELLO-------------------------");
		logger.info(client.getLocalServiceInstance().getHost()+","+client.getLocalServiceInstance().getServiceId());
		String returnStr = "hello from "+client.getLocalServiceInstance().getHost()+":"+client.getLocalServiceInstance().getPort();
		return returnStr;
	}
	
	@RequestMapping(value="/sendMsg",method=RequestMethod.GET)
	public String sendMsg()
	{
		logger.info("-------------------------------sendMsg-------------------------");
		for(int i=0;i<100;i++)
			mqSendService.send();
		return "success";
	}


}
